#!/bin/python
#-*- coding:utf-8 -*-
# Filename:    main.py
# Revision:    1.0
# Date:        2012-11-28
# Author:      simonzhang
# web:         www.simonzhang.net
# Email:       simon-zzm@163.com
##########
# 2012-11-8 add download Handler
### END INIT INFO
import os
import sys
import randomd
import time
import tornado.ioloop
import tornado.locale
import tornado.web
import tornado.database
from dbmodel import *


class DoorHandler():
    def get(self):
        _get_key = self.get_secure_cookie("d")
        _get_user_ip = self.request.remote_ip
        print _get_user_ip
        _get_time = time.localtime()
        _get_time_m = _get_time[1]
        _get_time_d = _get_time[2]
        _get_time_h = _get_time[3]
        _start_key = random.randint(00,99)
        _end_key = random.randint(00,99)
        _get_time_one = _get_time_m + _get_time_d
        _get_time_two = _get_time_d + _get_time_h
        if len(str(_get_time_one)) == 1:
            _get_key_one = "0%s" % _get_time_one
        else:
            _get_key_one = "%s" % _get_time_one
        if len(str(_get_time_two)) == 1:
            _get_key_two = "0%s" % _get_time_two
        else:
            _get_key_two = "%s" % _get_time_two
        _time_key = "%s%s%s%s" % (_start_key, _get_key_one, _get_key_two, _end_key)
        if _time_key == _get_key:
            key_file =open("key_ip.txt", "ab")
            key_file.write("%s\n" % _get_user_ip)
            key_file.close()
